<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 04.02.2015
 * Time: 16:52
 */

namespace Multilang\Panel\Tab;


abstract class BaseAction extends \Action {
	protected function run()
	{
		$this->response->items = $this->request->items;
		$this->response->langId = $this->request->langId;
	}

	public function renderItems($items, $langId, $filterFunctionName = '')
	{
		$outputHtml = '';
		$currentAction = '';
		foreach ($items as $item) {
			# Если задан фильтр и элемент не прошел фильтрацию - не рисуем его
			if (!empty($filterFunctionName) && (!method_exists($item, $filterFunctionName) || !$item->$filterFunctionName($langId))) {
				continue;
			}

			# Рисуем "заголовок" пачки переводов
			if ($item->action !== $currentAction) {
				$currentAction = $item->action;
				$outputHtml .= "<li><strong>$currentAction</strong></li>";
			}

			$outputHtml .= $this->action('.item',
				[
					'item' => $item,
					'langId' => $langId,
				]
			);
		}

		return $outputHtml;
	}
}